// +----------------------------------------------------------------------
// | CodeEngine
// +----------------------------------------------------------------------
// | Copyright 艾邦
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: TaoGe <liangtao.gz@foxmail.com>
// +----------------------------------------------------------------------
// | Version: 2.0 2019/7/11 15:22
// +----------------------------------------------------------------------
'use strict';

import Config from './config';
import Cache from './util/cache';
import Helper from './util/helper';
import Storage from './util/storage';
import Request from './util/request';
import Interface from './util/interface';
import Tool from "./util/tool";

class Rcr {

  // 初始化配置
  static config = Config.getInstance().getConfig();
  // 初始化存储类
  static storage = Storage.getInstance(Cache);

  constructor(config = null, storage = null) {
    if (config !== null) {
      Rcr.config = Config.setConfig(config);
    }
    if (config !== null) {
      Rcr.storage = Storage.getInstance(storage);
    }
    // 初始化核心函数库
    this.helper = Helper.getInstance(Rcr.config, Rcr.storage);

    // 初始化接口类
    this.interfaces = Interface.getInstance(Rcr.config, Rcr.storage, this.helper);

    // 初始化Request类
    this.raytheon = Request.getInstance(Rcr.config, Rcr.storage, this.helper, this.interfaces);
  }

  request(url, options = {}, cb = {}) {
    return this.raytheon.sendRaytheonRequest(url, options, cb);
  }
}

export default Rcr;

// new Rcr({
//   domain: 'kd.lthink.cn',
//   host: 'https://kd.lthink.cn/api/',
//   referer: 'kd.lthink.cn'
// }).request('app.v1.demo/index', {body: {page:1,time: new Date().getTime()}}, {
//   complete: res => {
//     console.log('1', res)
//   }
// });



